<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // 1. 创建 xhr 对象
    let xhr = new XMLHttpRequest();

    // 2. 准备事件，获取服务器响应结果
    xhr.onreadystatechange = function () {
      let res = xhr.responseText;
      console.log(res);
    }

    // 3. 设置请求方式和url地址
    xhr.open('POST', 'http://www.liulongbin.top:3006/api/addbook');

    // 4. 设置请求头
    xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

    // 5. 调用send发送请求
    let b = encodeURIComponent('红&黑');
    xhr.send('bookname=' + b + '&author=yyy&publisher=ssss');

  </script>
</body>

</html>